﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using System.Text;
	using System.Runtime.Serialization;

	/// <summary>
	/// A Data Transfer Object (DTO) that represents a direct message
	/// from twitter.
	/// </summary>
	/// <remarks>
	///		<para>
	///			It represents the &quot;direct_message&quot; element/object in both the xml and 
	///			json portions of the REST responses. 
	///		</para>
	/// </remarks>
	[DataContract(Name="direct_message")]
	public class DirectMessage : TwitterError 
	{
		private string createdAtString = "";
		private DateTime createdAt = DateTime.MinValue;

		/// <summary>
		/// Gets or sets the unique id of the direct message.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "id")]
		public int Id { get; set; }

		/// <summary>
		/// Gets or sets the text of the message.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;text&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "text")] 
		public string Text { get; set; }

		/// <summary>
		/// Gets or sets <see cref="System.String"/> value of the Date/Time the user was created.
		/// </summary>
		/// <remarks>
		///		<para>
		///		The string format from twitter is &quot;ddd MMM dd HH:mm:ss zzzz yyyy&quot;
		///		</para>
		/// </remarks>
		[DataMember(Name = "created_at")]
		public string CreatedAtString
		{
			get { return this.createdAtString; }
			set
			{
				this.createdAtString = value;
				if (!string.IsNullOrEmpty(value))
				{
					this.createdAt = DateTime.ParseExact(
						value, Status.TimeFormat,
						 CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
				}
			}
		}

		/// <summary>
		/// Gets or sets <see cref="System.DateTime"/> value of the created_at value from  
		/// twitter, if it can be parsed. 
		/// </summary>
		public DateTime CreatedAt
		{
			get { return this.createdAt; }
			set
			{
				this.createdAt = value;
				this.createdAtString = value.ToString(Status.TimeFormat);
			}
		}

		/// <summary>
		/// Gets or sets the sender id of the direct message.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;sender_id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "sender_id")]
		public int SenderId { get; set; }

		/// <summary>
		/// Gets or sets the recipient id of the direct message.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;recipient_id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "recipient_id")] 
		public int RecipientId { get; set; }

		/// <summary>
		/// Gets or sets the screen name of the sender.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;sender_screen_name&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name= "sender_screen_name")]
		public string SenderScreenName { get; set; }

		/// <summary>
		/// Gets or sets the screen name of the recipient.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;recipient_screen_name&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "recipient_screen_name")]
		public string RecipientScreenName { get; set; }

		/// <summary>
		/// Gets or sets the <see cref="Amplify.Twitter.User"/> recipient of the direct message.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;recipient&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "recipient")]
		public User Recipient { get; set; }

		/// <summary>
		/// Gets or sets the <see cref="Amplify.Twitter.User"/> sender of the direct message.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;sender&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="sender")]
		public User Sender { get; set; }
	}
}
